﻿using System;
using System.IO;

namespace _013_流之将内存流中的内容转换为字节数组
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] data = null;

            using (MemoryStream stream=new MemoryStream())
            {
                //用于产生随机字节
                Random rand = new Random();

                //写入20字节
                byte[] buffer = new byte[20];
                rand.NextBytes(buffer);
                stream.Write(buffer);

                //从流中重新提取字节数组
                data = stream.ToArray();
            }

            Console.WriteLine(BitConverter.ToString(data));



        }
    }
}
